<template>
  <div>
    <el-dialog title="任务完成情况" :visible.sync="dialogVisible" width="30%">
      <el-form ref="form" :model="form" label-width="80px">
        <div class="chax">
          <el-date-picker
            v-model="start"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
          <el-button @click="chaxun">查询</el-button>
        </div>
        <div class="task" v-for="(item, index) in list" :key="index">
          <span>{{ item.name }}</span>
          <span>{{ item.num }}/{{ item.total }}</span>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleOk('form')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { findById, update, getTask } from "@/api/sales";

export default {
  name: "edit",
  data() {
    return {
      dialogVisible: false,
      form: {
        id: "",
        name: "",
        phone: "",
        remark: "",
        status: "",
      },
      dateTime: [],
      start: "",
      Status: "",
      //状态数据
      options: [
        {
          value: "1",
          label: "离职",
        },
        {
          value: "0",
          label: "在职",
        },
      ],
      list: [],
      id: "",
    };
  },
  methods: {
    show(id) {
      console.log(123);
      this.dialogVisible = true;
      console.log(id);
      this.id = id;
      let a = {
        id: id,
        start: this.start,
      };
      getTask(a).then((res) => {
        console.log(res);
        if (res.status == 200) {
          this.list = res.result;
        }
      });
    },
    handleOk(form) {
      this.dialogVisible = false;
      this.$emit("Ok");
      //   this.$refs[form].validate((valid) => {
      //     if (valid) {
      //       if (this.form.phone != "") {
      //         var phone = /^1[3|4|5|7|8][0-9]\d{8}$/;
      //         if (!phone.test(this.form.phone)) {
      //           this.$message.warning("手机号格式错误, 请重新输入");
      //           return false;
      //         }
      //       }
      //       update(this.form).then((res) => {
      //         if (res.status === 200) {
      //           this.$emit("Ok");
      //           this.dialogVisible = false;
      //           this.$message.success("编辑成功");
      //         }
      //       });
      //     }
      //   });
    },
    change(e) {
      console.log(e);
      this.form.status = e;
    },
    chaxun() {
      var that = this;
      let form = {
        id: this.id,
        start: this.start,
      };
      getTask(form).then((res) => {
        console.log(res);
        if (res.status == 200) {
          this.list = res.result;
        }
      });
    },
  },
};
</script>

<style scoped>
.task {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
}
.task span:first-child {
  font-size: 20px;
}
.task span:last-child {
  font-size: 18px;
}
.chax {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
</style>
